package weifei.mall.entity;


import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.springframework.stereotype.Repository;


/**
 * -- 商品表
 * CREATE TABLE goods
 * (
 *     id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
 *     seller_id INT UNSIGNED NOT NULL COMMENT "卖家用户ID",
 *     name VARCHAR(256) NOT NULL COMMENT "商品名称",
 *     detail TEXT COMMENT "商品细节，可空",
 *     price FLOAT NOT NULL COMMENT "价格",
 *     freight INT DEFAULT 0 NOT NULL COMMENT "运费",
 *
 *     PRIMARY KEY (id),
 *     FOREIGN KEY (seller_id) REFERENCES user(id)
 * );
 *
 * */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("goods")
@Repository
public class Goods extends Model<Goods>
{
    @Getter
    public enum Column
    {
        ID("id"),
        SellerID("seller_id"),
        Name("name"),
        Detail("detail"),
        Price("price"),
        Freight("freight");

        final String name;
        Column(String name) { this.name = name; }
    }




    @TableId
    private Integer id;
    private Integer sellerId;
    @NotBlank @NotNull
    private String name;
    private String detail = "";
    @NotNull
    private Float price;
    private Integer freight = 0;

    public Goods() {}
    public Goods(int id) { this.id = id; }



    public static String getPicturesDirectoryPath(int sellerId, int goodsId)
    {
        var sb = new StringBuilder();
        sb
                .append("./goods/")
                .append(sellerId)
                .append("/")
                .append(goodsId)
                .append("/pictures");

        return sb.toString();
    }


}


